<template>
    <!-- <div :style="{'background': coverimg != '' ? coverimg : ''}"> -->
    <div>
        <router-view v-if="isRouterAlive"></router-view>
    </div>
</template>

<script>
    import {
        isNull
    } from './util/util'
    import {
        getToken
    } from './util/auth'
    export default {
        name: "App",
        provide () {
            return {
              reload: this.reload
            }
          },
        data() {
            return {
                zhihuUserInfo: null,
                isRouterAlive: true,
                coverimg: ''
            }
        },
        created() {
            // this.getWebCover()
        },
        components: {

        },
        computed: {

        },
        methods: {
            reload () {
              this.isRouterAlive = false
              this.$nextTick(function () {
                this.isRouterAlive = true
              })
            },
            // getWebCover () {
            //     const _this = this
            //     const params = {}
            //     _this.axios.post(_this.$API.ZHIHUAPI.getWebCover, _this.qs.stringify(params)).then((res) => {
            //         res = res.data
            //         // console.log(res)
            //         if (res.code === 10000) {
            //             if (res.hasOwnProperty('data') && Object.keys(res.data).length > 0) {
            //                 _this.coverimg = "url(" + res.data.coverimg + ")"
            //             }
            //         }
            //     }).catch(() => {

            //     })
            // }
        },
        mounted() {
            if (localStorage.getItem('zhihuUserInfo') && localStorage.getItem('zhihuUserInfo') !== 'null' && getToken()) {
                this.zhihuUserInfo = JSON.parse(localStorage.getItem('zhihuUserInfo'))
            }
            // 消息监听
            Echo.channel('sysnews')
                .listen('SystemNews', (e) => {
                    this.$notify({
                        title: e.title,
                        message: e.message,
                        type: e.messageType,
                        position: e.position,
                        duration: e.duration,
                    });
                })
                .listen('ReportNews', (e) => {
                    console.log(e)
                    if (!isNull(this.zhihuUserInfo) && this.zhihuUserInfo.id === e.data.to_id) {
                        this.$notify({
                            title: e.title,
                            message: e.message,
                            type: e.messageType,
                            position: e.position,
                            duration: e.duration,
                        });
                    }
                });
        }
    }
</script>

<style>

</style>
